import 'package:flutter/material.dart';

class LeaveDialog extends StatefulWidget {
  final String? content;
  final VoidCallback? onSure;

  const LeaveDialog({Key? key,this.content,this.onSure}) : super(key: key);

  @override
  _LeaveDialogState createState() => _LeaveDialogState();

  static show(BuildContext context,{VoidCallback? onSure}){
    showDialog(
        context: context,
        builder: (_)=>LeaveDialog(
          content: "是否结束带画",
          onSure: onSure,
        ),
    );
  }
}

class _LeaveDialogState extends State<LeaveDialog> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        margin: EdgeInsets.only(left: 50,right: 50),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(10)
        ),
        clipBehavior: Clip.hardEdge,
        child: Material(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              contentWgt,
              Divider(
                height: 0,
                thickness: 1,
                color: Color(0xFFD8D8D8),
              ),
              actionsWgt
            ],
          ),
        ),
      ),
    );
  }

  Widget get contentWgt {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 20),
      child: Text(
        "${widget.content}",
        style: TextStyle(
          fontSize: 15,
          color: Color(0xFF333333),
          fontWeight: FontWeight.bold
        ),
      ),
    );
  }


  Widget get actionsWgt {
    return Container(
      height: 50,
      child: Row(
        children: [
          Expanded(
            child: GestureDetector(
              child: Container(
                alignment: Alignment.center,
                color: Colors.white,
                child: Text(
                  "取消",
                  style: TextStyle(
                      fontSize: 15,
                      color: Color(0xFF333333),
                      fontWeight: FontWeight.bold
                  ),
                ),
              ),
              onTap: (){
                Navigator.pop(context);
              },
            ),
          ),
          Container(
            margin: EdgeInsets.symmetric(vertical: 5,horizontal: 0),
            width: 1,
            height: double.infinity,
            color: Color(0xFFD8D8D8),
          ),
          Expanded(
            child: GestureDetector(
              child: Container(
                alignment: Alignment.center,
                color: Colors.white,
                child: Text(
                  "确定",
                  style: TextStyle(
                      fontSize: 15,
                      color: Color(0xFFFC2C1C),
                      fontWeight: FontWeight.bold
                  ),
                ),
              ),
              onTap: (){
                if(widget.onSure != null) widget.onSure!.call();

                Navigator.pop(context);
              },
            ),
          ),
        ],
      ),
    );
  }
}

